home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18254 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: theory.lcs.mit.edu!wald
  2. From: wald@theory.lcs.mit.edu (David Wald)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: extending c++ to include type bool
  5. Date: 19 Apr 1996 13:46:44 GMT
  6. Organization: Theory of Computation, LCS, MIT
  7. Message-ID: <WALD.96Apr19094644@woodpecker.lcs.mit.edu>
  8. References: <bdsilver.829698454@extro> <3176C470.2647@cs.tu-berlin.de>
  9. NNTP-Posting-Host: woodpecker.lcs.mit.edu
  10. In-reply-to: Roman Lechtchinsky's message of Fri, 19 Apr 1996 00:38:40 +0200
  11.  
  12. In article <3176C470.2647@cs.tu-berlin.de> Roman Lechtchinsky
  13. <wolfro@cs.tu-berlin.de> writes:
  14. >Brett David Silverman wrote:
  15. >> The question: Is it possible to create a class bool, in such a way
  16. >> that it looks, smells, feels, talks, etc like the "real" bool?  To
  17. >> the extent that I can create this class so that I am guaranteed
  18. >> that the source will work, even though I can't see the source?
  19.  
  20. >I think one of the following should do ( depending on the compiler ):
  21. >enum bool { false, true };
  22. >or
  23. >enum { false, true };
  24. >typedef int bool;
  25.  
  26. (Didn't we just go through this?)  Thanks to overloading, it's not
  27. possible for a user-defined type to completely emulate the C++ bool.
  28. If you need a guarantee that some arbitrary code written with the C++
  29. bool type will work with your user-defined type, you're out of luck.
  30.  
  31. Consider:
  32.  
  33.   int f(bool);
  34.   int f(int);
  35.   int g(int a, int b) { return f(a == b); }
  36.  
  37. In a system without built-in bool, no user-defined bool will result in
  38. a call to f(bool).  You can't change the type of a built-in comparison
  39. operator.
  40.  
  41. -David
  42. -- 
  43. ============================================================================
  44. David Wald      http://theory.lcs.mit.edu/~wald/     wald@theory.lcs.mit.edu
  45. ============================================================================
  46.